<template>
  <div class="login-container">
    <div class="movespace">
      <div class="form">
        <h1>作业管理系统</h1>
        <div class="inputitem">
          <i class="icomoon ico-user"></i>
          <input type="text" placeholder="请输入账号" v-model="username" />
        </div>
        <div class="inputitem">
          <i class="icomoon ico-pwd"></i>
          <input type="password" placeholder="请输入密码" v-model="password" />
        </div>
        <div class="buttonlist">
          <button class="login-button" @click="login">立即登录</button>
          <button class="regist-button" @click="register">前往注册</button>
        </div>
      </div>
    </div>
    <vue-particles
      color="#dedede"
      :particleOpacity="0.7"
      :particlesNumber="80"
      shapeType="circle"
      :particleSize="4"
      linesColor="#3300CC"
      :linesWidth="1"
      :lineLinked="true"
      :lineOpacity="0.4"
      :linesDistance="150"
      :moveSpeed="3"
      :hoverEffect="true"
      hoverMode="grab"
      :clickEffect="true"
      clickMode="push"
    >
    </vue-particles>
    <background></background>
  </div>
</template>

<script>
import http from '@/api/loginapi'
import background from "@/views/Login/Background/index";
import check from './checkvalid'
export default {
  name: "login",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  components: {
    background,
  },
  methods: {
    register(){
      this.$router.push('register');
    },
    async login(){
      let msgresult=check(this.username,this.password);
      if(msgresult.result){
        let res=await http.sendlogin({account:this.username,pwd:this.password})
        if(res.status==200){
          this.$Toast({
            content: res.data.msg,
            type:res.data.type
          })
          if(res.data.type=="success"){
            localStorage.setItem("username",res.data.username)
            localStorage.setItem('path',res.data.path)
            //3秒后跳转到对应界面
            setTimeout(() => {
              this.$router.push(res.data.path)
            }, 3000);
          }
        }
      }
      else{
        this.$Toast({
          content: msgresult.msg,
          type: "error"
        })
      }
    }
  },
  mounted() {
    if(localStorage.getItem('path')){
      localStorage.setItem('path',"");
    }
  },
};
</script>

<style lang='less' scoped>
.login-container {
  height: 100%;
  width: 100%;
  position: absolute;
  .movespace {
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate3d(-50%, -50%, 0);
    .form {
      width: 460px;
      height: auto;
      margin: 0 auto;
      background-color: rgba(36, 36, 85, 0.5);
      box-shadow: 0 0 25px rgba(255, 255, 255, 0.5);
      padding: 35px 30px 35px;
      border-radius: 10px;
      h1 {
        font-weight: normal;
        text-align: center;
        margin-bottom: 20px;
        color: #d3d7f7;
      }
      .inputitem {
        display: flex;
        align-items: center;
        margin-bottom: 20px;
        border-bottom: 1px solid #d3d7f7;
        i {
          margin-right: 10px;
        }
        .ico-user {
          &::before {
            content: "\e971";
          }
        }
        .ico-pwd {
          &::before {
            content: "\e98d";
          }
        }
        input {
          color: #d3d7f7;
          outline: none;
          border: none;
          background-color: transparent;
          width: 100%;
          font-size: 16px;
        }
      }
      .buttonlist {
        position: absolute;
        left: 50%;
        top: 78%;
        transform: translateX(-50%);
        button {
          color: #ded7f7;
          width: 100px;
          margin: 0 10px;
          padding: 5px 10px;
          background-color: transparent;
          border: 1px solid #d3d7f7;
          cursor: pointer;
          border-radius: 5px;
          &:hover {
            color: #fff;
            background: #0090ff;
            border-color: #0090ff;
          }
        }
      }
    }
  }
}
</style>
